/**
 * 用户信息相关
 * @date: 2019-12-25

 */
import { getDvaApp } from "../iocUtils";
/**
 * 获取当前登录用户的角色信息
 */

export function getCurrentRole() {
  // eslint-disable-next-line no-underscore-dangle
  var state = getDvaApp()._store.getState();

  var _state$user = state.user,
      user = _state$user === void 0 ? {} : _state$user;
  var _user$currentUser = user.currentUser,
      currentUser = _user$currentUser === void 0 ? {} : _user$currentUser;
  var currentRoleId = currentUser.currentRoleId,
      currentRoleName = currentUser.currentRoleName,
      currentRoleLevel = currentUser.currentRoleLevel,
      currentRoleCode = currentUser.currentRoleCode;
  return {
    id: currentRoleId,
    name: currentRoleName,
    level: currentRoleLevel,
    code: currentRoleCode
  };
}
/**
 * 判断角色层级是否是租户层级
 */

export function isTenantRoleLevel() {
  var _getCurrentRole = getCurrentRole(),
      level = _getCurrentRole.level;

  return level !== 'site';
}
/**
 * 获取当前租户信息
 */

export function getCurrentTenant() {
  var state = getDvaApp()._store.getState();

  var _state$user2 = state.user,
      user = _state$user2 === void 0 ? {} : _state$user2;
  var _user$currentUser2 = user.currentUser,
      currentUser = _user$currentUser2 === void 0 ? {} : _user$currentUser2;
  var tenantId = currentUser.tenantId,
      tenantName = currentUser.tenantName,
      tenantNum = currentUser.tenantNum;
  return {
    tenantId: tenantId,
    tenantName: tenantName,
    tenantNum: tenantNum
  };
}
/**
 * 获取当前用户角色租户id
 */

export function getCurrentOrganizationId() {
  return getCurrentTenant().tenantId;
}
/**
 * 获取当前登录用户信息
 * @returns {object}
 */

export function getCurrentUser() {
  // eslint-disable-next-line no-underscore-dangle
  var state = getDvaApp()._store.getState();

  var _state$user3 = state.user,
      user = _state$user3 === void 0 ? {} : _state$user3;
  var _user$currentUser3 = user.currentUser,
      currentUser = _user$currentUser3 === void 0 ? {} : _user$currentUser3;
  return currentUser;
}
/**
 * 获取当前用户所属租户 ID
 */

export function getUserOrganizationId() {
  return getCurrentUser().organizationId;
}
/**
 * 获取当前登录用户id
 */

export function getCurrentUserId() {
  return getCurrentUser().id;
}
/**
 * 获取系统当前语言
 * @export
 * @returns
 */

export function getCurrentLanguage() {
  // eslint-disable-next-line no-underscore-dangle
  var state = getDvaApp()._store.getState();

  var _state$user4 = state.user,
      user = _state$user4 === void 0 ? {} : _state$user4;
  var _user$currentUser4 = user.currentUser,
      currentUser = _user$currentUser4 === void 0 ? {} : _user$currentUser4;
  var language = currentUser.language;
  return language;
}